<?php

    @header("Content-type:text/html;chaset=utf-8");
    @include_once("conn.php");
    $obj = array();

    $id = $_POST["id"];
    $type = $_POST["type"];

    if(!($id)){
        $obj["status"] = false;
        $obj["detail"] = "请输入完整的参数";
        exit(json_encode($obj));
    }

    if($type==1){
        $sql = "update `cart` set buyNum=buyNum + 1 where id = '$id'";
    }else if($type==0){
        $sql = "update `cart` set buyNum=buyNum - 1 where id = '$id'";
    }

    $bool = mysqli_query($conn,$sql);

    if(!$bool){
        $obj["status"] = false;
        $obj["detail"] = "fail";
        $obj["sql"] = $sql;
        exit(json_encode($obj));
    }

    $rows = mysqli_affected_rows($conn);

    if($rows>0){
        $obj["status"] = true;
        $obj["detail"] = "修改成功";   
    }else{
        $obj["status"] = false;
        $obj["detail"] = "修改失败，数据未改变";
    }
    exit(json_encode($obj));
?>